import java.sql.* ;

class Product
{

	CreateConnection cc ;


// Indexing in product table

	int id ;  // index-1 or it might be short code....depends
	String name ;  // index-2
	int cid ; // index-3  category id , not category bcz to do normalization using another table pcategory
			// index-1 a/c to table pcategory




	Product()
	{

		try{

				cc = new CreateConnection() ;

				}
				catch(Exception e)
			{}


	}


	void insertProduct(String[] s) //throws Exception
	{
		try
		{

		id = Integer.parseInt(s[0]) ;
		name = s[1] ;
		cid = Integer.parseInt(s[2]) ;

		System.out.println(id);
		System.out.println(name);
		System.out.println(cid);

		String sql = "insert into product values(?,?,?)" ;

		PreparedStatement p = cc.getStatement(sql) ;

		p.setInt(1,id) ;
		p.setString(2,name) ;

		p.setInt(3,cid) ;

		int x = p.executeUpdate() ;
		 if(x>0)
		  System.out.println("Product inserted successfully") ;
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}


	}

	void updateProduct(String[] s) throws Exception
		{

			id = Integer.parseInt(s[0]) ;
			name = s[1] ;
			cid = Integer.parseInt(s[2]) ;

			String sql = "update product set p_name = ? ,cid = ? where p_id= ?" ;


			PreparedStatement p = cc.getStatement(sql) ;

			p.setInt(3,id) ;
			p.setString(1,name) ;

			p.setInt(2,cid) ;


			int x = p.executeUpdate() ;
			 if(x>0)
			  System.out.println("Product updated successfully") ;



	}


	ResultSet getProductDetails() throws Exception
	{

		String sql = "select * from product" ;
		PreparedStatement p = cc.getStatement(sql) ;

		return p.executeQuery() ;

	}


	ResultSet getProductDetails(int id) throws Exception
		{

			String sql = "select * from product where p_id = ? " ;
			PreparedStatement p = cc.getStatement(sql) ;

			p.setInt(1,id) ;
			return p.executeQuery() ;

		}



}